var RequestInfo=function(url,options,data)
{
    this.options=options||{};
    if(url)
    {
        if(data)
        {
            switch(typeof(data))
            {
                case "string":
                    var formpair=data.split("&");
                    this.form=new Hashtable();
                    for(var i=0;i<formpair.length;i++)
                    {
                        var arr=formpair.split("=");
                        this.form.put(arr[0],arr[1]);
                    }
                    break;
                case "object":
                    for(var key in data)
                    {
                        this.form.put(key,data[key]);
                    }
                    break;
                default:
                    this.form=new Hashtable();
            }
        }
        
        this.query=new Hashtable();
        var indexOfQuestionMark=url.indexOf("?");
        if(indexOfQuestionMark>0)
        {
            this.path=url.substr(0,indexOfQuestionMark);
            this.search=url.substr(indexOfQuestionMark+1);
            var querypair=this.search.split("&");
            for(var i=0;i<querypair.length;i++)
            {
                if(querypair)
                {
                    var arr=this.search.split("=");
                        this.query.put(arr[0],arr[1]);
                }
            }
        }
        else
        {
            this.path=url;
        }
    }
    
    this.equal=function(requestInfo)
    {
        try
        {
            if(typeof(requestInfo)==="object")
            {
                if(this.path!=requestInfo.path)
                {
                    return false;
                }
                if(this.query && requestInfo.query)
                {
                    if (this.query.size()==requestInfo.query.size()) 
                    {
                        var keys=this.query.keys();
                        for(var i=0;i<keys.length;i++)
                        {
                            var value=requestInfo.query.get(keys[i]);
                            if(!value)
                            {
                                return false;
                            }
                            if(this.form && requestInfo.form) 
                            {
                                if (this.form.size()==requestInfo.form.size()) 
                                {
                                    for(var i=0;i<keys.length;i++)
                                    {
                                        var value=requestInfo.query.get(keys[i]);
                                        if(!value)
                                        {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                                return false;
                            }
                            return !this.form && !requestInfo.form;
                        }
                    }
                    return false;
                }
                else
                {
                    return (!this.query && !requestInfo.query);
                }
            }
            return false;        
        }
        catch(e)
        {
            return false;
        }
    }
    
    return this;
}

var requestCache=new Hashtable();
function sendajax(url,callbackFunction,options,postData)
{
    var result;
    if(options && options["EnableCache"]) 
    {
        var requestInfo=new RequestInfo(url,options,postData);
        for(var i=0; i<requestCache.keys().length;i++)
        {
            if(requestInfo.equal(requestCache.keys()[i]))
            {
               result=requestCache.get(requestCache.keys()[i]);
                if(typeof(callbackFunction)!="undefined")
                {
                    callbackFunction(result); 
                }
               break;
            }
        }
        if(!result)
        {                       
            $.ajax({async: true,
                    url: url, 
                        success: function(data)
                        {
                            var result=data;
                            requestCache.put(requestInfo,data); 
                            if(typeof(callbackFunction)!="undefined")
                            {
                                callbackFunction(result); 
                            }
                               
                        },
                        error: function () 
                        {
                            //throw exception
                        }
                    }); 
        }
    }
    else
    {
        $.ajax({
            async: true,
    //        type:"POST",
    //        data:postData,
            url: url, 
            success: function(data){
                    if(typeof(callbackFunction)!="undefined"){
                        var result=data;
                        if(typeof(callbackFunction)!="undefined")
                        {
                            callbackFunction(result); 
                        }
                    }
                },
            error: function () {
                //throw exception
            }
        });
    }
}